{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 安装依赖\n",
    "不同的Linux系统除了依赖的安装不同，后续的编译、安装步骤都一样。\n",
    "\n",
    "依赖很重要，否则安装完成后也会出问题，比如`No module named '_ctypes'`\n",
    "\n",
    "## 中标麒麟\n",
    "\n",
    "```sh\n",
    "yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel\n",
    "```\n",
    "\n",
    "## 银河麒麟\n",
    "\n",
    "```sh\n",
    "sudo apt update\n",
    "\n",
    "sudo apt-get install build-essential zlib1g-dev libbz2-dev libssl-dev libncurses5-dev libsqlite3-dev libreadline-dev tk-dev libgdbm-dev libdb-dev libpcap-dev xz-utils libexpat1-dev liblzma-dev libssl-dev openssl libffi-dev libc6-dev\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 下载python源码包\n",
    "\n",
    "python国内镜像：\n",
    "\n",
    "- 淘宝 https://npm.taobao.org/mirrors/python/\n",
    "- 华为 https://mirrors.huaweicloud.com/python/\n",
    "\n",
    "\n",
    "1. 新建文件夹 \n",
    "\n",
    "```sh\n",
    "mkdir /usr/local/python3\n",
    "```\n",
    "2. 解压\n",
    "\n",
    "```sh\n",
    "tar -zxvf Python-3.7.0.tgz\n",
    "```\n",
    "\n",
    "3. 将解压后的安装包移植到新文件夹\n",
    "\n",
    "```sh\n",
    "mv Python-3.7.0  /usr/local/python3\n",
    "```\n",
    "\n",
    "4. 执行配置文件，编译，编译安装\n",
    "```sh\n",
    "cd /usr/local/python3/Python-3.7.0  \n",
    "./configure --prefix=/usr/local/python3\n",
    "make -j8 && make install\n",
    "```\n",
    "\n",
    "5. 建立软连接\n",
    "\n",
    "```sh\n",
    "mv /usr/bin/python /usr/bin/python_bak # 其实直接rm /usr/bin/python删了也行 \n",
    "ln -s /usr/local/python3/bin/python3.7 /usr/bin/python\n",
    "ln -s /usr/local/python3/bin/pip3.7 /usr/bin/pip\n",
    "```\n",
    "\n",
    "6. 测试pip\n",
    "\n",
    "```sh\n",
    "pip install flask \n",
    "```\n",
    "\n",
    "7. 测试python\n",
    "\n",
    "```sh\n",
    "[root@mini Python-3.7.0]# python\n",
    "Python 3.7.0 (default, Jul 28 2018, 22:47:29) \n",
    "[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux\n",
    "Type \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n",
    ">>> print(\"hello world!\")\n",
    "hello world!\n",
    ">>> exit()\n",
    "\n",
    "[root@mini Python-3.7.0]# pip3 --version\n",
    "pip 10.0.1 from /usr/local/python3/lib/python3.7/site-packages/pip (python 3.7)\n",
    "```"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "165px"
   },
   "toc_section_display": true,
   "toc_window_display": true
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
